#ifndef __BALLADE_SOCKET_H__
#define __BALLADE_SOCKET_H__

#pragma once

#include <string>

#include <ballade/network/config.h>
#include <ballade/network/socket_error.h>
#include <ballade/network/input_stream.h>
#include <ballade/network/output_stream.h>

namespace Ballade
{
	
	namespace Network
	{
		using std::string;
		
		class NETWORK_API Socket
		{
		public:
			Socket();
			Socket(const char *ipaddr, const unsigned short port);
			
			~Socket();
			
			const InputStream &getInputStream() const;
			const OutputStream &getOutputStream() const;
			const int getSocketDescriptor() const;
			
			void setIPAddress(const char *ipaddr);
			void setPort(const unsigned short port);
			void setReadTimeout(const int val);
			void setWriteTimeout(const int val);
			const char* getIPAddress() const;
			const unsigned short& getPort() const;
			const int& getReadTimeout() const;
			const int& getWriteTimeout() const;
			const bool& isConnected() const;
			
			virtual void connect(const char *ipaddr, const unsigned short port) throw(SocketError);
			virtual void connect() throw(SocketError);
			virtual void close();
			
		protected:
			void setSocketDescriptor(const int sock);
			void setInputStream(InputStream *in);
			void setOutputStream(OutputStream *out);
			
			
		private:
			char _ipaddr[16];
			unsigned short _port;
			
			int _sock;
			int _readTimeout;
			int _writeTimeout;
			bool _isConnected;
			
			InputStream *_in;
			OutputStream *_out;
		};	
	}
}
#endif